let leaveTitle = " w(ﾟДﾟ)w 不要走！再看看嘛！";
let backTitle = "♪(^∇^*)欢迎肥来！";
let OriginTitile = document.title;
let titleTime;

document.addEventListener("visibilitychange", function () {
  if (document.hidden) {
    //离开当前页面时标签显示内容
    document.title = leaveTitle;
    clearTimeout(titleTime);
  } else {
    //返回当前页面时标签显示内容
    document.title = backTitle + OriginTitile;
    //两秒后变回正常标题
    titleTime = setTimeout(function () {
      document.title = OriginTitile;
    }, 2000);
  }
});

window.onscroll = function () {
  var topButton = document.getElementById("top");
  if (document.documentElement.scrollTop > 20) {
    topButton.style.display = "block"; // 显示按钮
  } else {
    topButton.style.display = "none"; // 隐藏按钮
  }
};

document.addEventListener("DOMContentLoaded", function () {
  document.getElementById("backToTop").addEventListener("click", function () {
    window.scrollTo({ top: 0, behavior: "smooth" });
  });
});

window.addEventListener("scroll", function () {
  var navMenu = document.querySelector(".nav-menu");
  if (window.pageYOffset > 0) {
    navMenu.classList.add("scrolled");
  } else {
    navMenu.classList.remove("scrolled");
  }
});
